import {HOST, HOST2, ROUTERHOST} from 'common/js/config'
import Request from 'common/js/request'
import Qs from 'qs'

var api = HOST2 + 'v1/app/';
var api2 = HOST + '?g=api/mission&m=clock&';
var api3 = HOST + '?g=api/public&m=index&';
var api4 = HOST + '?g=api/public&m=user&';
var api5 = HOST + '?g=api/shop&m=index&accesskey=519f9cab85c8059d17544947k361a827&';
var api6 = HOST + '?g=api/pv3&m=index&client=5&accesskey=519f9cab85c8059d17544947k361a827&';
var api7 = ROUTERHOST + '/api/v1/data/'
/*export function getTaskList () {
  const url = api + `a=mission_list`
  return Request.get(url)
}*/


export function getInviteInfo () {
  const url = api + `inviteInfo`
  return Request.get(url)
}


export function goods_search (params={}) {
  const url = api5 + `a=goods_search`;
  return Request.get(url, {
    params
  })
}

export function getGTCode () {
  const url = api + `validate/geetestInit`;
  return Request.get(url)
}

export function getCheckCode (data) {
  const url = api + `validate/getCode`;
  return Request.post(url, Object.assign({
    //scene: 'superNodeInvite'
  }, data),{
    transformRequest: [function (data) {
      // Do whatever you want to transform the data
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}

export function verifyCode (data) {
  const url = api + `acceptInvite`;
  return Request.get(url, {
    params: Object.assign({
      //scene: 'invite'
    }, data)
  })
}


export function getSuperNodeUser (params) {
  const url = api + `super/user/info`
  return Request.get(url, {
    params
  })
}

export function getMinerList (params) {
  const url = api + `super/user/incomeList`
  return Request.get(url, {
    params
  })
}

export function removeMiner (params) {
  const url = api + `super/user/removeMiner`
  return Request.get(url, {
    params
  })
}

export function getMinerListDetail (params) {
  const url = api + `super/user/minerList`
  return Request.get(url, {
    params
  })
}

export function getMinerNodecount (params) {
  const url = api + `super/user/nodeCount`
  return Request.get(url, {
    params
  })
}

export function getMinerProfitList (params) {
  const url = api + `super/user/incomeDetail`
  return Request.get(url, {
    params
  })
}

export function setMinerTop (params) {
  const url = api + `super/user/top`
  return Request.get(url, {
    params
  })
}


export function minerRegister (data) {
  const url = api + `passport/inviteReg`;
  return Request.post(url, data,{
    transformRequest: [function (data) {
      // Do whatever you want to transform the data
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}


//用户数据
export function getViewUser (params) {
  const url = api + `view/user`
  return Request.get(url, {
    params
  })
}


//充提数据
export function getViewCvnt (params) {
  const url = api + `view/cvnt`
  return Request.get(url, {
    params
  })
}


//质押数据
export function getViewPledge(params) {
  const url = api + `view/pledge`
  return Request.get(url, {
    params
  })
}

//节点数据
export function getViewNode(params) {
  const url = api + `view/node`
  return Request.get(url, {
    params
  })
}

//修改矿池余额
export function updateCvntTotal(params) {
  const url = api + `view/updateCvntTotal`
  return Request.get(url, {
    params
  })
}



// 单台设备日/时报表
export function deviceChart (data) {
  /*const url = api7 + `chart/router/user`;*/
  /*const url = api + `chart/router/user`;*/
  const url = api + `user/chart`;
  return Request.get(url, {
    params: data
  })
}





// 校验用户支付密码
export function checkAgentPayPassword2 (data) {
  const url = api + `validate/checkPayPassword`;
  // return Request({
  //   url,
  //   method: 'post',
  //   data: Qs.stringify(data)
  // })
  return Request.post(url, Qs.stringify(data))
}



// 校验用户支付密码
export function checkAgentPayPassword (data) {
  const url = api + `validate/checkPayPassword`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}


//超级节点列表
export function getSuperNodeList() {
  const url = api + `token/superNodeList?r=` + Date.now()
  return Request.get(url)
}

//令牌信息
export function getUserInfo() {
  const url = api + `token/userInfo?r=` + Date.now()
  return Request.get(url)
}

//质押临牌节点列表
export function getTokenNodeList(params) {
  const url = api + `token/nodeList?r=` + Date.now()
  return Request.get(url, {
    params
  })
}


//质押临牌节点列表
export function pledgeToken(params) {
  const url = api + `token/pledge?r=` + Date.now()
  return Request.get(url, {
    params
  })
}


//质押临牌节点列表
export function getSaleRentOrderList(params) {
  let url;
  if(params.mode == 'sale'){
    url = api + `token/saleOrderList?r=` + Date.now()
  }else{
    url = api + `token/rentOrderList?r=` + Date.now()
  }
  return Request.get(url, {
    params
  })
}


//租借广场列表
export function getRentSquare(params) {
  const url = api + `token/rentSquare?r=` + Date.now()
  return Request.get(url, {
    params
  })
}

//我的发布
export function getRentMyOrder(params) {
  const url = api + `token/rentMyOrder?r=` + Date.now()
  return Request.get(url, {
    params
  })
}


//发布订单
export function rentSubmitOrder(data) {
  const url = api + `token/rentSubmitOrder`
  return Request.post(url, data,{
    transformRequest: [function (data) {
      // Do whatever you want to transform the data
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}


//租借违规次数
export function getRentViolationNum(params) {
  const url = api + `token/rentViolationNum?r=` + Date.now()
  return Request.get(url, {
    params
  })
}


//出租令牌
export function rentToken(data) {
  const url = api + `token/rentToken`
  return Request.post(url, data,{
    transformRequest: [function (data) {
      // Do whatever you want to transform the data
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}


//租借违规次数
export function getRentCheckDeposit(params) {
  const url = api + `token/rentCheckDeposit?r=` + Date.now()
  return Request.get(url, {
    params
  })
}


//质押保证金
export function tokenPledging(params) {
  const url = api + `pledge/pledging?r=` + Date.now()
  return Request.get(url, {
    params
  })
}


//提取保证金
export function tokenDraw(params) {
  const url = api + `pledge/draw?r=` + Date.now()
  return Request.get(url, {
    params
  })
}

//获取钱包cvnt余额
export function platformTradeStepFirst(params) {
  const url = api + `token/platformTradeStepFirst?r=` + Date.now()
  return Request.get(url, {
    params
  })
}


//增加、提取保证金信息
export function depositInfo(params) {
  const url = api + `token/depositInfo?r=` + Date.now()
  return Request.get(url, {
    params
  })
}



//保证金明细
export function depositList(params) {
  const url = api + `token/depositList?r=` + Date.now()
  return Request.get(url, {
    params
  })
}


//撤销订单
export function rentCancelOrder(params) {
  const url = api + `token/rentCancelOrder?r=` + Date.now()
  return Request.get(url, {
    params
  })
}

//订单详情
export function rentOrderDetail(params) {
  const url = api + `token/rentOrderDetail`
  return Request.get(url, {
    params
  })
}


//未租到令牌数
export function notRentNum(params) {
  const url = api + `token/notRentNum`
  return Request.get(url, {
    params
  })
}



//矿工平均收益
export function minerAverageRevenue(params={}) {
  const url = api + `token/minerAverageRevenue?r=` + Date.now()
  return Request.get(url, {
    params
  })
}


//令牌信息
export function getPledgeInfo(type) {
  const url = api + `token/refreshNodeInfo?r=` + Date.now()
  return Request.get(url, {
    params: {
      type
    }
  })
}


//令牌信息
export function getSuperNodeInfo(superUid) {
  const url = api + `super/user/superNodeInfo?r=` + Date.now()
  return Request.get(url, {
    params: {
      superUid
    }
  })
}


// 极验初始化/* uid, token, uid=${uid}&token=${token}& */
export function becomeSuperNodeMiner (params={}) {
  const url = api + `super/user/superInviteCode?r=` + Date.now()
  return Request.get(url, {
    params
  })
}


//检查是否满足退出条件
export function checkSecede() {
  const url = api + `super/user/checkSecede?r=` + Date.now()
  return Request.get(url)
}


//退出超级节点
export function secede(data) {
  const url = api + `super/user/secede`
  return Request.post(url, data,{
    transformRequest: [function (data) {
      // Do whatever you want to transform the data
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}
